use App\Post; use App\Policies\PostPolicy; use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. *应用策略映射 * @var array */ protected $policies = [ 'App\Model' => 'App\Policies\ModelPolicy', //放在这里直接映射了 下面就不用在boot里挨个写了 那样太凌乱了 Post::class=>PostPolicy::class, ];
/** * Register any application authentication / authorization services. * * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return void */ public function boot(GateContract $gate) { parent::registerPolicies($gate);